Skip to content

[PM-47415] fix: Initialize shared flows once instead of in property getters - #7638

Open
merrick-cr wants to merge 1 commit into
mainfrom
PM-47415/share-in-get-fix
Open

merrick-cr wants to merge 1 commit into
mainfrom
PM-47415/share-in-get-fix

Conversation

@merrick-cr

@merrick-cr merrick-cr commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

🎟️ Tracking

PM-47415

📔 Objective

Fixes the 25 existing NoSharingInPropertyGetter detekt violations (rule added in #7615) in app, authenticator and data. Each was a property getter calling stateIn, so every access built a new shared flow and launched a new collector.

  • Converted the getters to single property initializers.
  • SettingsRepositoryImpl.vaultLastSyncStateFlow used to be rebuilt for whichever user was active at access time. It now follows activeUserIdChangesFlow with flatMapLatest, so it tracks user switches and emits null when there is no active user.
  • VaultLockManagerImpl.isActiveUserUnlockingFlow changed from Lazily to Eagerly. UserStateManagerImpl reads its .value without a guaranteed collector, and a single Lazily instance would stay frozen at its construction-time value.
  • FirstTimeActionManagerImpl.allSettingsBadgeCountFlow moved below the flows it combines, since initializers run in declaration order.
  • Tests updated where they relied on per-access flows (authenticator SettingsRepositoryTest stubs every flow collected at construction, FlightRecorderManagerTest, UserNotificationPolicyManagerTest). Added tests for vaultLastSyncStateFlow following the active user and for each shared flow returning the same instance on every access.

Detekt is clean and the unit tests pass for the affected app, authenticator and data suites.

📸 Screenshots

Not applicable, no UI changes.

…tters

Convert getters that call stateIn/shareIn into single property initializers to satisfy NoSharingInPropertyGetter. Rework vaultLastSyncStateFlow to follow the active user, make isActiveUserUnlockingFlow eager, and update tests that relied on per-access flows.
@merrick-cr
merrick-cr requested review from a team and david-livefront as code owners November 20, 2026 20:36
@merrick-cr merrick-cr added app:password-manager Bitwarden Password Manager app context app:authenticator Bitwarden Authenticator app context t:tech-debt Change Type - Tech debt labels Nov 20, 2026
@github-actions github-actions Bot added t:bug Change Type - Bug and removed t:tech-debt Change Type - Tech debt labels Nov 20, 2026
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.20290% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.96%. Comparing base (6542cdc) to head (04a347d).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...data/platform/repository/SettingsRepositoryImpl.kt 92.75% 0 Missing and 5 partials ⚠️
...data/platform/repository/SettingsRepositoryImpl.kt 89.58% 2 Missing and 3 partials ⚠️
...anager/policy/UserNotificationPolicyManagerImpl.kt 93.75% 0 Missing and 1 partial ⚠️
...twarden/data/vault/manager/VaultLockManagerImpl.kt 91.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #7638       +/-   ##
===========================================
+ Coverage   69.22%   86.96%   +17.74%     
===========================================
  Files         898      897        -1     
  Lines       65001    65272      +271     
  Branches     9320     9402       +82     
===========================================
+ Hits        44994    56765    +11771     
+ Misses      17482     5036    -12446     
- Partials     2525     3471      +946     
Flag Coverage Δ
app-data 19.06% <66.66%> (+19.06%) ⬆️
app-ui-auth-tools 18.81% <0.00%> (+0.01%) ⬆️
app-ui-platform 16.02% <0.00%> (+<0.01%) ⬆️
app-ui-vault 27.01% <0.00%> (+0.01%) ⬆️
authenticator 6.11% <27.62%> (+0.05%) ⬆️
lib-core-network-bridge 4.16% <0.00%> (+<0.01%) ⬆️
lib-data-ui 1.33% <3.86%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app:authenticator Bitwarden Authenticator app context app:password-manager Bitwarden Password Manager app context t:bug Change Type - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant